package com.itheima.reggie.exception;

import com.itheima.reggie.common.R;
import com.itheima.reggie.service.exception.CustomException;
import com.itheima.reggie.service.exception.DuplicateUserException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//用于标识当前类为rest风格对应的异常处理器
@Slf4j
public class ProjectException {

    @ExceptionHandler(DuplicateUserException.class)
    public R doDuplicateUserException(DuplicateUserException due){
        //记录日志
        log.info("当前异常: {}",DuplicateUserException.class);

        return R.error(due.getMsg());

    }

    //删除菜品类或套餐时可能产生的异常
    @ExceptionHandler(CustomException.class)
    public R doCustomException(CustomException ce){
        //记录日志
        log.info("当前异常: {}",CustomException.class);

        return R.error(ce.getMsg());
    }
}
